package com.lyf.scm.plan.api.controller;

import com.github.pagehelper.PageInfo;
import com.lyf.scm.plan.api.dto.OperationLogRecordDTO;
import com.lyf.scm.plan.domain.service.OperationLogRecordService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: huangtao
 * @Description: 操作日志
 * @Date: create in 2020/10/5
 */
@Api(tags = "操作日志记录")
@RequestMapping("/api/v1/operationLogRecord")
@RomeController
public class OperationLogRecordController {

    @Resource
    private OperationLogRecordService operationLogRecordService;

    @PostMapping("/getOperationLogs")
    @ApiOperation(value = "查询操作日志")
    public Response<PageInfo<OperationLogRecordDTO>> getOperationLogs(@RequestBody OperationLogRecordDTO operationLogRecord){
        return Response.builderSuccess(operationLogRecordService.getOperationLogs(operationLogRecord));
    }

    @PostMapping("/insertOperationLog")
    @ApiOperation(value = "新增操作日志数据")
    public Response<OperationLogRecordDTO> insertOperationLog(@RequestBody OperationLogRecordDTO operationDto){
        return Response.builderSuccess(operationLogRecordService.insertOperationLog(operationDto));
    }

    @PutMapping("/updateOperationLog")
    @ApiOperation(value = "编辑操作日志数据")
    public Response<OperationLogRecordDTO> updateOperationLog(@RequestBody OperationLogRecordDTO operationDto){
        return Response.builderSuccess(operationLogRecordService.updateOperationLog(operationDto));
    }

    @PostMapping("/bigData/Initiating")
    @ApiOperation(value = "发起大数据定时任务，将状态调整为进行中")
    public Response bigDataInitiating() {
        operationLogRecordService.bigDataInitiating();
        return Response.builderSuccess(null);
    }

    @PostMapping("/opLog/Initiating")
    @ApiOperation(value = "发起删除任务（成功的操作数据），将状态调整为进行中")
    public Response opLogInitiating(@RequestBody List<Long> ids) {
        operationLogRecordService.opLogInitiating(ids);
        return Response.builderSuccess(null);
    }

    @DeleteMapping
    @ApiOperation(value = "删除指定标识数据")
    public Response rmByOpSign(@RequestBody List<OperationLogRecordDTO> operationLogRecordDTOs) {
        operationLogRecordService.rmByOpSign(operationLogRecordDTOs);
        return Response.builderSuccess(null);
    }
    @PostMapping("/updateToDel")
    @ApiOperation(value = "修改操作日志状态为已删除")
    public Response updateToDel(@RequestParam("opSign") String opSign){
        operationLogRecordService.updateToDel(opSign);
        return Response.builderSuccess(null);
    }
}
